package com.haiya.lod;

import java.util.ArrayList;
import java.util.List;

public class Demeter1 {
    public static void main(String[] args) {
        SchoolManager schoolManager = new SchoolManager();
        schoolManager.printAllEmployee(new CollegeManager());
    }
}

/**
 * 学校总部员工
 */
class Employee {
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

/**
 * 学院员工
 */
class CollegeEmployee {
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

/**
 * 学校总部管理类
 * 这个类的直接朋友:
 * 1. Employee
 * 2. CollegeManager
 *
 * 而CollegeEmployee不是它的直接朋友，是一个陌生类，是以局部变量的方式出现的这个类中的， 违反了迪米特法则。
 */
class SchoolManager {
    public List<Employee> getAllEmployee() {
        ArrayList<Employee> employees = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Employee employee = new Employee();
            employee.setId("学校总部员工ID = " + i);
            employees.add(employee);
        }

        return employees;
    }

    public void printAllEmployee(CollegeManager sub) {
        List<CollegeEmployee> allEmployee = sub.getAllEmployee();
        System.out.println("--------------学院员工--------------------");
        for (CollegeEmployee collegeEmployee : allEmployee) {
            System.out.println(collegeEmployee.getId());
        }

        List<Employee> schoolEmps = getAllEmployee();
        System.out.println("--------------学校总部员工--------------------");
        for (Employee schoolEmp : schoolEmps) {
            System.out.println(schoolEmp.getId());
        }
    }
}

/**
 * 管理学院员工的管理类
 */
class CollegeManager {
    public List<CollegeEmployee> getAllEmployee() {
        ArrayList<CollegeEmployee> employees = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            CollegeEmployee employee = new CollegeEmployee();
            employee.setId("学院员工ID = " + i);
            employees.add(employee);
        }

        return employees;
    }
}